//
//  HMMainTabBarController.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/9.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMMainTabBarController.h"
#import "HMHomeTableViewController.h"
#import "HMDiscoverTableViewController.h"
#import "HMMessageTableViewController.h"
#import "HMProfileTableViewController.h"
#import "HMMainTabBar.h"
#import "HMComposeVC.h"

@interface HMMainTabBarController ()

@end

@implementation HMMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    HMMainTabBar *tabBar = [[HMMainTabBar alloc] init];
    [self setValue:tabBar forKeyPath:@"tabBar"];
    tabBar.addBtnBlock = ^{
        
        HMComposeVC *composeVC = [[HMComposeVC alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:composeVC];
        [self presentViewController:nav animated:YES completion:nil];
       
    };
    [self setupChildViewControllers];
    

}

+(instancetype)mainTabBarController
{
    return [[self alloc] init];
}

-(void)setupChildViewControllers
{
    [self addChildVC:[[HMHomeTableViewController alloc] init] imageName:@"tabbar_home" title:@"首页"];
    [self addChildVC:[[HMMessageTableViewController alloc] init] imageName:@"tabbar_message_center" title:@"消息"];
    [self addChildVC:[[HMDiscoverTableViewController alloc] init] imageName:@"tabbar_discover" title:@"发现"];
    [self addChildVC:[[HMProfileTableViewController alloc] init] imageName:@"tabbar_profile" title:@"我"];
}

-(void)addChildVC:(UIViewController *)viewController imageName:(NSString *)imageName title:(NSString *)title
{
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    viewController.title = title;
    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [viewController.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [self addChildViewController:nav];
}

@end
